﻿package client;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JEditorPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import server.ComHouseInterface;

import client.Configuration;


public class ComMiddleGUI extends JDialog {

	private JPanel contentPane;
	private JTable table;

	/**
	 * Launch the application.
	 */
	/*public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ComMiddleGUI frame = new ComMiddleGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
*/
	/**
	 * Create the frame.
	 */
	public ComMiddleGUI() {
		setTitle("Middle");
		setModalityType(ModalityType.APPLICATION_MODAL);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JButton btnNewButton = new JButton("\u4E70");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				ComSetKeyGUI csg = new ComSetKeyGUI();
				csg.setLocationRelativeTo(null);
				csg.setVisible(true);
				
			}
		});
		btnNewButton.setBounds(34, 215, 93, 23);
		contentPane.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("\u4E0D\u4E70");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				ComHouseInforGUI chg = new ComHouseInforGUI();
				chg.setLocationRelativeTo(null);
				chg.setVisible(true);
				
			}
		});
		btnNewButton_1.setBounds(297, 215, 93, 23);
		contentPane.add(btnNewButton_1);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(67, 32, 301, 151);
		contentPane.add(scrollPane);
		
		Configuration config=new Configuration();
		String rmiAddress=config.getRmiAddress();
		try {
			ComHouseInterface comHouse = (ComHouseInterface) Naming.lookup(rmiAddress+"ComHouseList");
			
			Object [][] a = new Object [10][];
			for(int i = 1;i <= 10; i++){
				String str = comHouse.getKey(i+10);
				a[i-1] = new Object[2];
				a[i-1][0] = new Integer(i+10);
				if(str == null)
					a[i-1][1] = new String("false");
				else
					a[i-1][1] = new String("true");
			}
			
			table = new JTable();
			table.setModel(new DefaultTableModel(
				a,
				new String[] {
					"\u623F\u53F7", "\u662F\u5426\u5356\u51FA"
				}
			));
			scrollPane.setViewportView(table);
		} catch (MalformedURLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (RemoteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (NotBoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		
	}

}
